//
//  SetSystemViewController.m
//  MyProject
//
//  Created by dllo on 15/10/31.
//  Copyright (c) 2015年 蓝鸥0825. All rights reserved.
//

#import "SetSystemViewController.h"
#import "LView.h"
#import "AppDelegate.h"
#import "Save.h"
#import "QRCodeGenerator.h"      //二维码

#define HEIGHT self.view.frame.size.height
#define WIDTH self.view.frame.size.width
@interface SetSystemViewController ()

@property(nonatomic, retain)UIScrollView *scrollView;

@property(nonatomic, retain)UIView *alertView;

@end

@implementation SetSystemViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.title = @"系统设置";
    self.view.backgroundColor = [UIColor colorWithWhite:0 alpha:0.1];
    self.navigationController.navigationBar.translucent = NO;

 
    
    
    
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
    [self.view addSubview:self.scrollView];
    [self.scrollView release];
    self.scrollView.backgroundColor = [UIColor colorWithWhite:0.9 alpha:1];
    
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT / 100 * 30)];
    [self.scrollView addSubview:imageView];
    [imageView release];
    imageView.image = [UIImage imageNamed:@"bj.png"];
    
    [self button1];
    [self button2];
    [self button3];
    [self button4];
}





#pragma mark    button1的设置
- (void)button1{
    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeSystem];
    button1.frame = CGRectMake(0, HEIGHT / 100 * 33, WIDTH, HEIGHT / 100 * 6);
    [self.scrollView addSubview:button1];
    button1.backgroundColor = [UIColor whiteColor];
    [button1 addTarget:self action:@selector(naightAction:) forControlEvents:UIControlEventTouchUpInside];
    
    UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, WIDTH / 10, HEIGHT / 100 * 6)];
    [button1 addSubview:imageView1];
    [imageView1 release];
    imageView1.image = [UIImage imageNamed:@"yejianmoshi.jpg"];
    
    UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH / 10 * 2, 0, WIDTH / 10 * 7, HEIGHT / 100 * 6)];
    [button1 addSubview:label1];
    [label1 release];
    label1.text = @"夜间模式";
    
    UIImageView *imageView_1 = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH / 10 * 9, HEIGHT / 100, WIDTH / 10, HEIGHT / 100 * 4)];
    [button1 addSubview:imageView_1];
    [imageView_1 release];
    imageView_1.image = [UIImage imageNamed:@"jt.jpg"];
}


- (void)naightAction:(UIButton *)button{
    
    [(AppDelegate *)[UIApplication sharedApplication].delegate change];
    
}





#pragma mark    button2的设置
- (void)button2 {
    
    UIButton *button2 = [UIButton buttonWithType:UIButtonTypeSystem];
    button2.frame = CGRectMake(0, HEIGHT / 100 * 42, WIDTH, HEIGHT / 100 * 6);
    [self.scrollView addSubview:button2];
    button2.backgroundColor = [UIColor whiteColor];
    [button2 addTarget:self action:@selector(button2Action) forControlEvents:UIControlEventTouchUpInside];
    
    UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, WIDTH / 10, HEIGHT / 100 * 6)];
    [button2 addSubview:imageView2];
    [imageView2 release];
    imageView2.image = [UIImage imageNamed:@"qingchuhuancun.jpg"];
    
    UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH / 10 * 2, 0, WIDTH / 10 * 7, HEIGHT / 100 * 6)];
    [button2 addSubview:label2];
    [label2 release];
    label2.text = @"清理缓存";
    
    UIImageView *imageView_2 = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH / 10 * 9, HEIGHT / 100, WIDTH / 10, HEIGHT / 100 * 4)];
    [button2 addSubview:imageView_2];
    [imageView_2 release];
    imageView_2.image = [UIImage imageNamed:@"jt.jpg"];
    
}


- (void)button2Action {
    
    [Save deleteModel];
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示信息" message:@"清除缓存成功" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        
    }];
    [alert addAction:cancel];
    [self presentViewController:alert animated:YES completion:^{
        
    }];
    
}






#pragma mark    button3的设置
- (void)button3 {
    
    UIButton *button3 = [UIButton buttonWithType:UIButtonTypeSystem];
    button3.frame = CGRectMake(0, HEIGHT / 100 * 51, WIDTH, HEIGHT / 100 * 6);
    [self.scrollView addSubview:button3];
    button3.backgroundColor = [UIColor whiteColor];
    [button3 addTarget:self action:@selector(button3Action) forControlEvents:UIControlEventTouchUpInside];
    
    UIImageView *imageView3 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, WIDTH / 10, HEIGHT / 100 * 6)];
    [button3 addSubview:imageView3];
    [imageView3 release];
    imageView3.image = [UIImage imageNamed:@"erweima.jpg"];
    
    UILabel *label3 = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH / 10 * 2, 0, WIDTH / 10 * 7, HEIGHT / 100 * 6)];
    [button3 addSubview:label3];
    [label3 release];
    label3.text = @"二维码";
    
    UIImageView *imageView_3 = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH / 10 * 9, HEIGHT / 100, WIDTH / 10, HEIGHT / 100 * 4)];
    [button3 addSubview:imageView_3];
    [imageView_3 release];
    imageView_3.image = [UIImage imageNamed:@"jt.jpg"];
    
}

- (void)button3Action {
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示信息" message:@"请期待更好的体验效果, 确认扫描后方二维码" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        
    }];
    [alert addAction:cancel];
    [self presentViewController:alert animated:YES completion:^{
        
        self.alertView = [[UIView alloc] initWithFrame:self.view.frame];
        [self.view addSubview:self.alertView];
        [self.alertView release];
        self.alertView.backgroundColor = [UIColor whiteColor];
        self.alertView.alpha = 0.8;
        
        
        UIImage *img = [QRCodeGenerator qrImageForString:@"每一天†美食" imageSize:200];
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH / 100 * 30, HEIGHT / 100 * 20, WIDTH / 100 * 40, HEIGHT / 100 * 20)];
        imageView.image = img;
        [self.alertView addSubview:imageView];
        [imageView release];
        
        UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
        [button setTitle:@"返回" forState:UIControlStateNormal];
        button.frame = CGRectMake(WIDTH / 100 * 40, HEIGHT / 100 * 65, WIDTH / 100 * 20, HEIGHT / 100 * 5);
        [self.alertView addSubview:button];
        [button addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
        button.layer.cornerRadius = 10;
        button.backgroundColor = [UIColor grayColor];
        
    }];
}

- (void)click {
    
    self.alertView.hidden = YES;
    
}




#pragma mark    button4的设置
- (void)button4{
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(0, HEIGHT / 100 * 62, WIDTH, HEIGHT / 100 * 6);
    [self.scrollView addSubview:button];
    button.backgroundColor = [UIColor whiteColor];
    [button addTarget:self action:@selector(buttonBanbenxinxi) forControlEvents:UIControlEventTouchUpInside];
    
    
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, WIDTH / 10, HEIGHT / 100 * 6)];
    [button addSubview:imageView];
    [imageView release];
    imageView.image = [UIImage imageNamed:@"banben.png"];
    
    UILabel *label3 = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH / 10 * 2, 0, WIDTH / 10 * 7, HEIGHT / 100 * 6)];
    [button addSubview:label3];
    [label3 release];
    label3.text = @"版本信息检测";
    
    UIImageView *imageView_3 = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH / 10 * 9, HEIGHT / 100, WIDTH / 10, HEIGHT / 100 * 4)];
    [button addSubview:imageView_3];
    [imageView_3 release];
    imageView_3.image = [UIImage imageNamed:@"jt.jpg"];
}



- (void)buttonBanbenxinxi{
    
    NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
    
    NSString *appVersion = [infoDic objectForKey:@"CFBundleVersion"];
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"版本信息" message:[NSString stringWithFormat:@"version:%@.0", appVersion] preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        
    }];
    [alert addAction:cancel];
    [self presentViewController:alert animated:YES completion:^{
        
    }];
    
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}








@end







